

//
//  ZFNewConView.swift
//  WeiBoAPP
//
//  Created by 张学飞 on 2019/2/28.
//  Copyright © 2019 zxf. All rights reserved.
//

import UIKit

class ZFNewConView: UIView {

    @IBOutlet weak var welcomlabelTopCons: NSLayoutConstraint!
    @IBOutlet weak var welcomLabel: UILabel!
    
    
    //    override init(frame: CGRect) {
//        super.init(frame: frame)
//        backgroundColor = UIColor.red
//    }
//
    //initwithcode刚从xib的二进制文件将视图数据加载完成，
    //还没和代码连线简历起关系，开发时不要在这个方法中处理UI问题
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
//        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        
//        self.backgroundColor = UIColor.red
    }

    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        self.removeFromSuperview()
    }
    
    
    
    //创建nib
    class func welcomeView() ->ZFNewConView {
        let nib = UINib(nibName: "ZFNewConView", bundle:nil)
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! ZFNewConView

        return v 
    }
    
    //视图添加到window 表示视图已经显示
    override func didMoveToWindow() {
        super.didMoveToWindow()
        /**
         //视图是使用自动布局来设置的，只是设置了j约束
         //当视图被添加到窗口上是，根据父视图的大小，计算的约束值，更新控件的位置
         //layoutIfNeed 会根据当前的约束直接更新控件的位置
         //执行之后，控件所在的位置就是 XIB中布局的位置
         **/
        
        //更新约束
        self.layoutIfNeeded()
        welcomlabelTopCons.constant = welcomLabel.top - 60
        UIView.animate(withDuration: 2.0,
                       delay: 0,
                       options: [],
                       animations: {
                        self.layoutIfNeeded()
                        
        }) { (_) in
            //结束完成回调
        }
        
        
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
